# Create your views here.
from django.shortcuts import render_to_response, get_object_or_404,HttpResponseRedirect
from django.template import RequestContext
from Godthaab_v1.Apps.Products.models import Type, Product, ProductDetail, Staff, Url, Fish,JobRequest
from django.views.decorators.csrf import csrf_exempt

def index(request):
    return render_to_response('index.html')

def products(request):
    types = Type.objects.all()
    fishes = Fish.objects.all()
    context = {
        'types': types,
        'fishes': fishes,
    }
    return render_to_response('products/products.html', context)

def getProductsByType(request, typeId):
    return render_to_response('products/type.html', {'type': Type.objects.get(pk=typeId)})

def getProductsByFish(request, fishId):
    return render_to_response('products/fish.html', {'fish': Fish.objects.get(pk=fishId)})

def getStaff(request):
    return render_to_response('staff.html', {'staff': Staff.objects.all()} )

def getUrl(request):
    return render_to_response('url.html', {'urls': Url.objects.all()})

def getThanks(request):
    return render_to_response('thanks.html')

@csrf_exempt
def getJobRequest(request):
    if request.method == 'POST':
        form = JobRequest(request.POST)
        if form.is_valid():
            form.save()
            return HttpResponseRedirect('/job-request/thanks/')
    else:
        form = JobRequest()
    return render_to_response('jobrequest.html',
                              {'form': form},
                              context_instance=RequestContext(request))



